import { request } from '../request';

/**
 * 日志
 *
 * @param userName User name
 * @param password Password
 * @param code Verification code
 * @param uuid Unique identifier for verification code
 */
export function fetchLogin(userName: string, password: string, code?: string, uuid?: string) {
  return request<Api.Auth.LoginToken>({
    url: '/auth/login',
    method: 'post',
    data: {
      userName,
      password,
      code,
      uuid
    }
  });
}

/**
 * 用户退出登录
 * 调用后台管理端的logout接口
 */
export function fetchLogout() {
  return request({
    url: '/logout',
    method: 'get'
  });
}

export function fetchGetAuthList(params?: Api.SystemSetting.LogSearchParams) {
  return request<Api.SystemSetting.LogList>({
    url: '/sys/log/getRoleList',
    method: 'get',
    params
  });
}


/** Get user info */
export function fetchGetUserInfo() {
  return request<Api.Auth.UserInfo>({ url: '/auth/getUserInfo' });
}

/**
 * Refresh token
 *
 * @param refreshToken Refresh token
 */
export function fetchRefreshToken(refreshToken: string) {
  return request<Api.Auth.LoginToken>({
    url: '/auth/refreshToken',
    method: 'post',
    data: {
      refreshToken
    }
  });
}

/**
 * return custom backend error
 *
 * @param code error code
 * @param msg error message
 */
export function fetchCustomBackendError(code: string, msg: string) {
  return request({ url: '/auth/error', params: { code, msg } });
}
